#!/usr/bin/env python3

import random
from time import sleep, ctime
import threading
import sys

class CNC(threading.Thread):
    def __init__(self, freq=None):
        super().__init__()

        self.cnc_data = 0
        self.update_freq = 0.01 if not freq else freq  # unit: second
        self.update_time = 0
        # 激活刷新线程


    def read_runtime_value(self):
        msg = "@{} --> cnc-data value: {}, loop_time now is: {}".format(ctime(), self.cnc_data, self.update_time)
        return msg

    def run(self):
        while True:
            self.cnc_data = random.randint(0, 1000)
            self.update_time += 1
            sleep(self.update_freq)


if __name__ == "__main__":
    cnc = CNC()
    cnc.start()
    loop_time = 5
    while loop_time > 0:
        loop_time -= 1
        input("After enter any keycode, you'll get a runtime cnc_simulate value: ")
        print(cnc.read_runtime_value())
    # cnc.join()
    print("join")
    sys.exit()
    print("exit")  # it will never be print...
